<?php
namespace Admin\Controller;

use Think\Controller;

class SyndataController extends CommonController
{
    public static $limit = 15;

    public function index()
    {
        $where = 'is_show = 1';
        if ($_GET) {
            $time = I('get.');
            if (isset($time['s_time']) && $time['s_time']) {
                $where .= " and "."time >= " . $time['s_time'];
            }

            if (isset($time['e_time']) && $time['e_time'] && $time['s_time'] != $time['e_time']) {
                $where .= ' and ' . "time <= " . $time['e_time'];
            }

        }
        
        $limit = self::$limit;
        $count = M('syn')->where($where)->count();
        $Page = new \Org\Bjy\Page($count, $limit);
        $show = $Page->show();
        $list = M('syn')->where($where)->order('time desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
        
        
        foreach ($list as $k => $v) {
            if (isset($v['content'])) {
                $list[$k]['content'] = urldecode($v['content']);
                $list[$k]['content'] = str_replace('&','&amp' , $list[$k]['content']);
                $list[$k]['title'] = sub($list[$k]['content']);
            }
        }

        $count = count($list);
        $this->assign('datas', $list);
        $this->assign('page', $show);
        $this->assign('count', $count);
        $this->display();
    }
    public function del(){
        $get = I('get.');
        if(isset($get['delete'])){
            $id = $get['delete'];
            if(!$id){
                return false;
            }
            $result = M('syn')->where(['id'=>$id])->save(['is_show'=>0]);
            if($result){
                $this->redirect("admin/Syndata/index");
            }else{
                $this->error('删除失败','admin/Syndata/index');
            }
        }
    }

}